var elder = {
	elderId: '',
	name: '',
	sex: '',
	birthday: '',
	peoples: '',
	cardId: '',
	maritalStatus: '',
	registeredResidence: '',
	liveAddress: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	remark: '',
	personType: '',
	personTypeName: '',
	beHospitalStatus: '',
	elderType: '',
};

var elderView = {
	data: elder
};

var elder_vue_vm = new Vue({
	el: '#elder_vue_vm',
	data: elderView
});

function saveElderBaseInfo() {
	/*长者*/
	if(isEmpty(elderView.data.name)) {
		alert('请输入长者姓名');
		return;
	}
	if(elderView.data.sex!=0 && elderView.data.sex!=1) {
		alert('请输入长者性别');
		return;
	}
	if(isEmpty(elderView.data.year)) {
		alert('请输入长者出生年');
		return;
	}
	if(isEmpty(elderView.data.month)) {
		alert('请输入长者出生月');
		return;
	}
	if(isEmpty(elderView.data.day)) {
		alert('请输入长者出生日');
		return;
	}
	if(isEmpty(elderView.data.cardId)) {
		alert('请输入长者身份证号');
		return;
	}
	if(!checkIdCard(elderView.data.cardId)) {
		alert('长者身份证号格式有误');
		return;
	}
	
	/*家属*/
	if(isEmpty(elderFamilyMemberView.data.name)) {
		alert('请输入家属姓名');
		return;
	}
	if(elderFamilyMemberView.data.sex!=0 && elderFamilyMemberView.data.sex!=1) {
		alert('请输入家属性别');
		return;
	}
	if(isEmpty(elderFamilyMemberView.data.year)) {
		alert('请输入家属出生年');
		return;
	}
	if(isEmpty(elderFamilyMemberView.data.month)) {
		alert('请输入家属出生月');
		return;
	}
	if(isEmpty(elderFamilyMemberView.data.day)) {
		alert('请输入家属出生日');
		return;
	}
	if(isEmpty(elderFamilyMemberView.data.cardId)) {
		alert('请输入家属身份证号');
		return;
	}
	if(!checkIdCard(elderFamilyMemberView.data.cardId)) {
		alert('家属身份证号格式有误');
		return;
	}
	if(isEmpty(elderFamilyMemberView.data.relationship)) {
		alert('请输入家属与长者的关系');
		return;
	}
	if(isEmpty(elderFamilyMemberView.data.phoneNumber)) {
		alert('请输入家属手机号');
		return;
	}
	
	/*紧急联系人*/
	if(isEmpty(elderMemContactsView.data.name)) {
		alert('请输入紧急联系人姓名');
		return;
	}
	if(elderMemContactsView.data.sex!=0 && elderMemContactsView.data.sex!=1) {
		alert('请输入紧急联系人性别');
		return;
	}
	if(isEmpty(elderMemContactsView.data.year)) {
		alert('请输入紧急联系人出生年');
		return;
	}
	if(isEmpty(elderMemContactsView.data.month)) {
		alert('请输入紧急联系人出生月');
		return;
	}
	if(isEmpty(elderMemContactsView.data.day)) {
		alert('请输入紧急联系人出生日');
		return;
	}
	if(isEmpty(elderMemContactsView.data.cardId)) {
		alert('请输入紧急联系人身份证号');
		return;
	}
	if(!checkIdCard(elderMemContactsView.data.cardId)) {
		alert('紧急联系人身份证号格式有误');
		return;
	}
	if(isEmpty(elderMemContactsView.data.relationship)) {
		alert('请输入紧急联系人与长者的关系');
		return;
	}
	if(isEmpty(elderMemContactsView.data.phoneNumber)) {
		alert('请输入紧急联系人手机号');
		return;
	}
	
	elderView.data.sex = (elderView.data.sex==''? 0: parseInt(elderView.data.sex));
	elderView.data.personType = (elderView.data.personType==''? 0: parseInt(elderView.data.personType));
	elderView.data.beHospitalStatus = (elderView.data.beHospitalStatus==''? 1: parseInt(elderView.data.beHospitalStatus));
	elderView.data.elderType = (elderView.data.elderType==''? 1: parseInt(elderView.data.elderType));
	elderFamilyMemberView.data.sex = (elderFamilyMemberView.data.sex==''? 0: parseInt(elderFamilyMemberView.data.sex));
	elderMemContactsView.data.sex = (elderMemContactsView.data.sex==''? 0: parseInt(elderMemContactsView.data.sex));
	
	elderView.data.birthday = elderView.data.year + '-' + elderView.data.month + '-' + elderView.data.day;
	elderFamilyMemberView.data.birthday = elderFamilyMemberView.data.year + '-' + elderFamilyMemberView.data.month + '-' + elderFamilyMemberView.data.day;
	elderMemContactsView.data.birthday = elderMemContactsView.data.year + '-' + elderMemContactsView.data.month + '-' + elderMemContactsView.data.day;
	
	elderView.data.cardId = elderView.data.cardId;
	elderFamilyMemberView.data.cardId = elderFamilyMemberView.data.cardId;
	elderMemContactsView.data.cardId = elderMemContactsView.data.cardId;

	save_basic(path+'/elder/saveElderBaseInfo',
		{elder:elderView.data, elderFamilyMember:elderFamilyMemberView.data, elderMemContacts:elderMemContactsView.data},
		function() {
			alert('保存成功');
			findAll();
	});
}

function findAll() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/elder/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/elder/deleteBatch');
}
